/**
 * --------------- js异步分页 ---------------
 */

define([
	"publicBusiness/layerPc",
	"artlib",
	"publicTool/ajax",
	"publicTool/method",
	"mCustomScrollbar",
], function(layerPc, template, ajax, Method, mCustomScrollbar){
	var Pagination = function(opt){
		// 各个方法
		var _this = this;
		// ==初始化配置项
		this.config(opt);
		// ==初始化数据
		// this.requestData(function(){
		// 	// 渲染数据列表
		// 	_this.renderDataList();
		// 	// 渲染页码区域
		// 	_this.renderPageZone();
		// 	// 关闭弹窗
		// 	lay.closeAll("loading");
		// });
	}

	// 初始化配置项
	Pagination.prototype.config = function(opt){
		// 设置初始配置项
		var defaults = {
			api_name: "", //请求接口项目名称
			url: "", //请求数据的地址

			form_id: "", //请求数据的表单id

			page_folder: "page_folder", //分页区域容器id
			page_folder_className: "", //分页区域容器class名称--850宽对应分页class（pagination_folder in_frame）

			page_cur_number_hidden: "page_cur_number_hidden", //当前显示的页码数,隐藏域的id
			page_page_size_hidden: "page_page_size_hidden", //当前显示条数,隐藏域的id
			page_cur_number_name: "page_infos][curr_page", //当前显示的页码数,隐藏域的name
			page_page_size_name: "page_infos][page_size", //当前显示条数,隐藏域的name

			condition_merchant_id: {isPass: true, id:"conditionMerchantid", name: "conditions][merchant_id", value: localStorage.merchant_id}, //商家id
			condition_platform_id: {isPass: false, id:"conditionPlatform", name: "conditions][platform_id", value: localStorage.platform_id}, //平台id
			condition_identification: {isPass: false, id:"conditionIdentification", name: "conditions][identification", value: ""}, //标识

			is_show_page_zone: true, //是否显示分页区域
			is_show_page_size: false, //是否显示每页多少条数据

			page_number: 1, //当前显示的页码数
			page_size: 10, //每页显示的条数
			page_show_start: "page_start_page", //当前显示数据起始值的id
			page_show_end: "page_end_page", //当前显示数据终止值的id
			page_number_total: "page_total_page", //总数据条数的id
			page_pages_total: "page_page_total", //总数据页数的id
			page_input: "page_page_input", //页码输入框的id
			page_go_btn: "page_page_jump", //页码更换按钮的id
			page_first_btn: "page_first_page", //去首页按钮的id
			page_last_btn: "page_last_page", //去末页按钮的id
			page_prev_btn: "page_prev_page", //前一页按钮的id
			page_next_btn: "page_next_page", //后一页按钮的id
			page_change_btn_class: "change_page", //页码切换按钮的类名

			page_tpl_title: "page_tpl_title", //表头模板容器的id
			art_tpl_box: "art_tpl_box", //数据模板容器的id

			mock_test: false, //模拟假数据测试-hack ajax工具类的url传递方法
			page_data_list_folder: "page_data_list_folder", //数据列表容器的id
			is_show_con_blank: true, //是否显示数据列表为空的样式
			con_blank_type: "", //数据列表为空--内容类型
			con_blank_style: "", //数据列表为空时的样式--行间样式(正常些样式eg： margin-top:150px;)
			con_blank_content_defined: "", //数据列表为空时的自定义空白模板(必须是被html标签包裹的文本值，不然会不被渲染)
			fix_class: "", //数据列表为空时的样式的修正样式
			btn_call_before: "", //任意页码切换按钮的回调函数(在渲染数据之前执行)
			btn_call: "", //任意页码切换按钮的回调函数(在渲染数据之后执行)

			isSetHorScroll: false, //是否设置横向滚动条
			HorScrollClass: "width100_horizontal_scroll" //设置横向滚动条的样式（如果样式不同可以自定义最终替换）
		};
		// 得到最终的配置项
		this.config = $.extend(true, defaults, opt);

		// 根据配置项初始化元素
		this.form_zone = $("#" + this.config.form_id); //form表单元素

		this.form_cur_input_hidden = $("#" + this.config.page_cur_number_hidden); //当前页码隐藏域
		this.page_page_size_hidden = $("#" + this.config.page_page_size_hidden); //当前显示条数隐藏域
		this.cur_num = this.form_cur_input_hidden.val() - 0; //当前显示页码
		this.page_size = this.page_page_size_hidden.val() - 0; //当前显示页码条数

		if(this.config.condition_merchant_id.isPass){
			this.condition_merchant_id = $("#" + this.config.condition_merchant_id.id); //商家id隐藏域
		}
		if(this.config.condition_platform_id.isPass){
			this.condition_platform_id = $("#" + this.config.condition_platform_id.id); //平台id隐藏域
		}
		if(this.config.condition_identification.isPass){
			this.condition_identification = $("#" + this.config.condition_identification.id); //权限id隐藏域
		}

		this.page_data_list = $("#" + this.config.page_data_list_folder); //数据列表容器
		this.art_box = $("#" + this.config.art_tpl_box); //数据列表模板容器
		this.page_tpl_title = $("#" + this.config.page_tpl_title); //表头模板容器

		this.page_folder = $("#" + this.config.page_folder); //分页区域容器
		if(this.page_folder.length == 0){
			this.page_data_list.after("<div id="+ this.config.page_folder +"></div>");
			this.page_folder = $("#" + this.config.page_folder); //分页区域容器
		}

		this.initInputHidden();
		this.initInputMerchantPlatform();
		this.setFormDataSerilalize();
	}

	// 初始化--当前页和页码条数隐藏域
	Pagination.prototype.initInputHidden = function(){
		// 设置隐藏域--当前页和每页条数对象--对象创建及初始化值
		if(!this.form_cur_input_hidden.length && this.config.is_show_page_zone){
			this.form_zone.append("<input type='hidden' name="+ this.config.page_cur_number_name +" id="+ this.config.page_cur_number_hidden +" value="+ this.config.page_number +" />");
			this.cur_num = this.config.page_number;
			this.form_cur_input_hidden = $("#" + this.config.page_cur_number_hidden); //当前页码隐藏域
		}
		if(!this.page_page_size_hidden.length && this.config.is_show_page_zone){
			this.form_zone.append("<input type='hidden' name="+ this.config.page_page_size_name +" id="+ this.config.page_page_size_hidden +" value="+ this.config.page_size +" />");
			this.page_size = this.config.page_size;
			this.page_page_size_hidden = $("#" + this.config.page_page_size_hidden); //当前显示条数隐藏域
		}
	}

	// 初始化--商家id，平台id，标识
	Pagination.prototype.initInputMerchantPlatform = function(){
		if( this.condition_merchant_id && !this.condition_merchant_id.length){
			this.form_zone.append("<input type='hidden' name="+ this.config.condition_merchant_id.name +" id="+ this.config.condition_merchant_id.id +" value="+ this.config.condition_merchant_id.value +" />");
			this.condition_merchant_id = $("#" + this.config.condition_merchant_id.id); //商家id
		}
		if( this.condition_platform_id && !this.condition_platform_id.length){
			this.form_zone.append("<input type='hidden' name="+ this.config.condition_platform_id.name +" id="+ this.config.condition_platform_id.id +" value="+ this.config.condition_platform_id.value +" />");
			this.condition_platform_id = $("#" + this.config.condition_platform_id.id); //平台id
		}
		if( this.condition_identification && !this.condition_identification.length){
			this.form_zone.append("<input type='hidden' name="+ this.config.condition_identification.name +" id="+ this.config.condition_identification.id +" value="+ this.config.condition_identification.value +" />");
			this.condition_identification = $("#" + this.config.condition_identification.id); //权限
		}
	}

	// 获取表单数据系列化的值
	Pagination.prototype.setFormDataSerilalize = function(){
		//获取表单系列化的值
		this.form_data_string = this.form_zone.serialize().replace(/\+/g, '%20');
	}

	// 表单系列化值--设置当前页码值
	Pagination.prototype.setFormDataSerilalizePageNum = function(){
		if(this.config.is_show_page_zone){
			var sStr = this.config.page_cur_number_name.replace(/\[/g, "\\[");
			sStr = sStr.replace(/\]/g, "\\]");
			var rReg = new RegExp(sStr + "=\\d+", "g");
			this.form_data_string = decodeURIComponent(this.form_data_string).replace(rReg, this.config.page_cur_number_name + "=" + this.cur_num);
		}
	}

	// 表单系列化值--设置每页条数
	Pagination.prototype.setFormDataSerilalizePageSize = function(){
		if(this.config.is_show_page_zone){
			var sStr = this.config.page_page_size_name.replace(/\[/g, "\\[");
			sStr = sStr.replace(/\]/g, "\\]");
			var rReg = new RegExp(sStr + "=\\d+", "g");
			this.form_data_string = decodeURIComponent(this.form_data_string).replace(rReg, this.config.page_page_size_name + "=" + this.page_size);
		}
	}

	// 请求数据
	Pagination.prototype.requestData = function(call,num){
		var _this = this;
		// 请求特定的页码数据
		if(num && typeof num == "number"){
			this.cur_num = num;
			this.form_cur_input_hidden.val(this.cur_num);
			this.setFormDataSerilalizePageNum();
		}
		// 定义发送异步请求的对象
		var oDataRequest = {
			data: {
				api_name: this.config.api_name,
				uri: this.config.url,
				data: Method.unserialize( decodeURIComponent(this.form_data_string) )
			}
		};
		// 如果是模拟假数据
		if(this.config.mock_test){
			oDataRequest.url = this.config.url;
		}

		// 异步请求初始数据
		ajax(oDataRequest, function(data){
			_this.data_infor = data;
			// 存储总页数-hack分页字段不一致
			_this.total_page_page = _this.data_infor.result.total_page ? _this.data_infor.result.total_page : _this.data_infor.result.page_num;

			if(_this.total_page_page < _this.cur_num && _this.total_page_page > 0){
				_this.cur_num = _this.total_page_page;
				_this.form_cur_input_hidden.val(_this.cur_num);
			}
			call && call(_this.data_infor, _this);
		});
	}

	// 渲染数据列表
	Pagination.prototype.renderDataList = function(){
		var oData = this.data_infor;
		if(this.data_infor.result.data.length){ //数据不为空
			var sHtml = template(this.config.art_tpl_box, oData.result);
			// 渲染表头
			if(this.page_tpl_title.length){
				var sTplTitle = this.page_tpl_title.html();
				// 渲染数据
				this.page_data_list.html(sTplTitle + sHtml);
			}else{
				// 渲染数据
				this.page_data_list.html(sHtml);
			}
				
			// 设置横向滚动条
			this.setHorScroll();
			
			// hack样式问题
			if(this.config.fix_class){
				this.page_data_list.removeClass(this.config.fix_class);
			}

		}else{ //数据为空
			if(this.config.is_show_con_blank){
				if(this.config.con_blank_content_defined){  // 是否是自定义模板
					this.setContentBlank("defined");
					// 设置横向滚动条
					this.setHorScroll();
				}else{
					this.setContentBlank(this.config.con_blank_type);
				}
				
			}else{
				this.page_data_list.html("");
			}
		}
	}

	// 设置横向滚动条
	Pagination.prototype.setHorScroll = function(){
		// 设置横向滚动条
		if(this.config.isSetHorScroll){
			this.page_data_list.addClass(this.config.HorScrollClass);
			this.page_data_list.mCustomScrollbar({
                horizontalScroll:true,
                advanced:{
                    autoExpandHorizontalScroll:true
                }
            });
		}
	}

	//数据为空提示消息
	Pagination.prototype.setContentBlank = function(type){
		var sContent = '<div class="content_blank" style="'+ this.config.con_blank_style +'">'; //此部分为空内容公共部分
		switch(type){
			case 1:
				sContent += 	'<div class="pic no_search_condition"></div>'
								+'<p class="con_search">请输入搜索条件</p>'
								+'<p class="con mar_t_15">执行搜索操作后为您统计相关数据</p>'
							+'</div>';
				break;
			case "defined":
				sContent = "";
				sContent += this.config.con_blank_content_defined;
				break;
			default:
				sContent += 	'<div class="pic common"></div>'
								+'<p class="con">暂无相关数据</p>'
							+'</div>';

		}
		this.page_data_list.html($(sContent));
		// hack样式问题
		if(this.config.fix_class){
			this.page_data_list.addClass(this.config.fix_class);
		}
	}

	// 计算当前开始条数和结束条数
	Pagination.prototype.calculateShowPage = function(){
		var iStart = (this.cur_num - 1) * this.page_size + 1;
		var iEnd = this.cur_num * this.page_size;
		return {start: iStart, end: iEnd};
	}

	// 渲染页码区域
	Pagination.prototype.renderPageZone = function(){
		if(!this.config.is_show_page_zone){
			return;
		}
		if(this.data_infor.result.data.length){ //数据不为空
			var _this = this;
			var iNum = this.cur_num;
			var sPageTpl = this.getPageTpl(); //获得表单区域模板

			// 拼装数据
			sPageTpl = sPageTpl.replace(/{page_show_start}/g, this.calculateShowPage().start ); //替换起始值
			sPageTpl = sPageTpl.replace(/{page_show_end}/g, this.calculateShowPage().end ); //替换终止值
			sPageTpl = sPageTpl.replace(/{page_number_total}/g, this.data_infor.result.total); //替换总数据条数
			sPageTpl = sPageTpl.replace(/{page_pages_total}/g, this.total_page_page); //替换总数据页数

			// 渲染除了数字按钮的页码
			this.page_folder.html($(sPageTpl));
			if(this.config.page_folder_className){
				this.page_folder.addClass(this.config.page_folder_className);
			}
			
			// 渲染页面后得到相关按钮
			this.form_btn_first = $("#" + this.config.page_first_btn); //去首页按钮
			this.form_btn_last = $("#" + this.config.page_last_btn); //去末页按钮
			this.form_btn_prev = $("#" + this.config.page_prev_btn); //前一页按钮
			this.form_btn_next = $("#" + this.config.page_next_btn); //后一页按钮
			this.form_btn_go = $("#" + this.config.page_go_btn); //go按钮
			this.form_btn_go_inp = $("#" + this.config.page_input); //go按钮输入框

			// 渲染每页显示的条数selcet框
			if(this.config.is_show_page_size){
				var sPageSize = this.getPageSizeChangeTpl();
				$(sPageSize).insertAfter("#" + this.config.page_go_btn);
				// 获取到切换条数select框
				this.form_page_size = $("#page_page_size");
				// 设置option的选中值
				this.form_page_size.find("option").each(function(){
					if(($(this).html())-0 == _this.page_size){
						$(this).attr("selected", true);
						return;
					}
				})
				// 绑定页码条数事件
				this.bindPageSizeChange();
			}

			// 渲染数字切换页码

			if(iNum == 1){ //如果是第一页
				this.renderFirstPageNumBtn(iNum);
			}else if(iNum == this.total_page_page){ //如果是最后一页
				this.renderLastPageNumBtn(iNum);
			}else{ //如果是中间页
				this.renderCenterPageNumBtn(iNum);
			}

			// 页码数字按钮绑定事件
			this.bindChangeBtn();
			// 首页按钮绑定事件
			this.bindFirBtn();
			// 末页按钮绑定事件
			this.bindLastBtn();
			// 前一页按钮绑定事件
			this.bindPrevBtn();
			// 后一页按钮绑定事件
			this.bindNextBtn();
			// 跳转按钮绑定事件
			this.bindJumpBtn();
			// 跳转页码输入框绑定事件
			this.bindJumpInput();
		}else{ //数据为空
			this.page_folder.html("");
		}
	}

	// 渲染页码--从第一页开始渲染
	Pagination.prototype.renderFirstPageNumBtn = function(num){
		// 渲染页码
		var sPageBtns = "";

		for(var i = 1; i <= this.total_page_page; i++){
			var sPageBtnTpl = this.getChangeBtnTpl();
			if(num == i){
				sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, " on");
			}else{
				sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
			}
			sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
			sPageBtns += sPageBtnTpl;

			if(i == 10){
				break;
			}
		}
		$(sPageBtns).insertAfter("#" + this.config.page_prev_btn);
	}

	// 渲染页码--从最后页开始渲染
	Pagination.prototype.renderLastPageNumBtn = function(num){
		// 渲染页码
		var sPageBtns = "";

		for(var i = this.total_page_page-9; i <= this.total_page_page; i++){
			var sPageBtnTpl = this.getChangeBtnTpl();
			if(i > 0){
				if(num == i){
					sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, " on");
				}else{
					sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
				}
				sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
				sPageBtns += sPageBtnTpl;
			}
		}
		$(sPageBtns).insertAfter("#" + this.config.page_prev_btn);
	}

	// 渲染页码--从中间页开始渲染
	Pagination.prototype.renderCenterPageNumBtn = function(num){
		var sPageBtns = "";
		var sPageBefore = ""; //前4页
		var sPageCur = ""; //当前页
		var sPageAfter = ""; //后5页
		// 渲染页码
		
		if(this.total_page_page >= 10){ //如果大于等于10页
			// 渲染前4页
			if(num > this.total_page_page - 5){
				for(var i = num-(10-(this.total_page_page-num+1)); i < num; i++){
					var sPageBtnTpl = this.getChangeBtnTpl();
					sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
					sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
					sPageBefore += sPageBtnTpl;
				}
			}else{
				for(var i = num-4; i < num; i++){
					if(i > 0){
						var sPageBtnTpl = this.getChangeBtnTpl();
						sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
						sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
						sPageBefore += sPageBtnTpl;
					}
				}
			}

			// 渲染后5页
			if(num < 5){ //如果前面少于5页
				// 渲染后5页
				for(var i = num+1; i <= 10; i++){
					if(i <= this.total_page_page){
						var sPageBtnTpl = this.getChangeBtnTpl();
						sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
						sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
						sPageAfter += sPageBtnTpl;
					}
				}
			}else{
				// 渲染后5页
				for(var i = num+1; i <= num+5; i++){
					if(i <= this.total_page_page){
						var sPageBtnTpl = this.getChangeBtnTpl();
						sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
						sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
						sPageAfter += sPageBtnTpl;
					}
				}
			}
				
			//渲染当前页
			if(num == this.cur_num){
				var sPageBtnTpl = this.getChangeBtnTpl();
				sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, " on");
				sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, num);
				sPageCur += sPageBtnTpl;
			}
			
			sPageBtns = sPageBefore + sPageCur + sPageAfter;
		}else{
			for(var i = 1; i <= this.total_page_page; i++){
				var sPageBtnTpl = this.getChangeBtnTpl();
				if(num == i){
					sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, " on");
				}else{
					sPageBtnTpl = sPageBtnTpl.replace(/{status}/g, "");
				}
				sPageBtnTpl = sPageBtnTpl.replace(/{page_num}/g, i);
				sPageBtns += sPageBtnTpl;
			}
		}

		$(sPageBtns).insertAfter("#" + this.config.page_prev_btn);
	}

	// 页码区域模板
	Pagination.prototype.getPageTpl = function(){
		var sPageTpl = '';
			sPageTpl = '<p class="tip_page_show">'
							+ '显示第<span class="start_page" id="'+ this.config.page_show_start +'">{page_show_start}</span>到第<span class="end_page" id="'+ this.config.page_show_end +'">{page_show_end}</span>条记录，总共<span class="total_page" id="'+ this.config.page_number_total +'">{page_number_total}</span>条记录'
						+ '</p>'
						+ '<div class="pagination mar_t_10">'
							+ '<div class="page_mark">'
								+ '<a href="javascript:;" class="first_page" id="'+ this.config.page_first_btn +'"></a>'
								+ '<a href="javascript:;" class="prev_page" id="'+ this.config.page_prev_btn +'"></a>'
								+ '<a href="javascript:;" class="next_page" id="'+ this.config.page_next_btn +'"></a>'
								+ '<a href="javascript:;" class="last_page" id="'+ this.config.page_last_btn +'"></a>'
							+ '</div>'
							+ '<div class="page_infor">'
								+ '<p>'
									+ '共<span id="'+ this.config.page_pages_total +'">{page_pages_total}</span>页，去<input type="text" name="" id="'+ this.config.page_input +'" />页'
									+ '<a href="javascript:;" class="page_jump" id="'+ this.config.page_go_btn +'">Go</a>'
								+ '</p>'
							+ '</div>'
						+ '</div>';
		return sPageTpl;
	}

	// 页码区页码切换按钮模板
	Pagination.prototype.getChangeBtnTpl = function(){
		var sPageBtnTpl = '<a href="javascript:;" data-page="{page_num}" class="'+ this.config.page_change_btn_class +'{status}">{page_num}</a>';
		return sPageBtnTpl;
	}

	// 每页显示的条数selcet框模板
	Pagination.prototype.getPageSizeChangeTpl = function(){
		var sPageSize = '<span class="mar_l">'
							+'每页'
						+'</span>'
						+'<select name="" id="page_page_size" class="show_page_sel" style="margin:0 5px;">'
							+'<option value="5">5</option>'
							+'<option value="10">10</option>'
							+'<option value="20">20</option>'
							+'<option value="30">30</option>'
							+'<option value="40">40</option>'
							+'<option value="50">50</option>'
						+'</select>'
						+'<span class="t_sp">条</span>';
		return sPageSize;
	}

	// （1-n）页码切换绑定事件
	Pagination.prototype.bindChangeBtn = function(){
		var _this = this;
		var aBtn = $("a." + _this.config.page_change_btn_class);
		
		aBtn.click(function() {
			if($(this).hasClass("on")){
				return;
			}
			// 页面切换
			_this.cur_num = $(this).attr("data-page") - 0;
			_this.form_cur_input_hidden.val(_this.cur_num);
			aBtn.removeClass("on");
			$(this).addClass("on");
			_this.setFormDataSerilalizePageNum();
			_this.requestData(function(oData){
				// 自定义的回调函数（渲染数据之前执行）
				_this.config.btn_call_before && _this.config.btn_call_before(oData);
				_this.renderPageZone();
				_this.renderDataList();
				// 自定义的回调函数
				_this.config.btn_call && _this.config.btn_call(oData);
				// 关闭弹窗
				layer.closeAll("loading");
			});
		});
	}

	// 首页按钮绑定事件
	Pagination.prototype.bindFirBtn = function(){
		var _this = this;
		_this.form_btn_first.click(function() {
			if(_this.cur_num == 1){
				return;
			}else{
				_this.cur_num = 1;
				_this.form_cur_input_hidden.val(_this.cur_num);
				_this.setFormDataSerilalizePageNum();
				_this.requestData(function(oData){
					// 自定义的回调函数（渲染数据之前执行）
					_this.config.btn_call_before && _this.config.btn_call_before(oData);
					_this.renderPageZone();
					_this.renderDataList();
					// 自定义的回调函数
					_this.config.btn_call && _this.config.btn_call(oData);
					// 关闭弹窗
					layer.closeAll("loading");
				});
			}
		});
	}

	// 末页按钮绑定事件
	Pagination.prototype.bindLastBtn = function(){
		var _this = this;
		_this.form_btn_last.click(function() {
			if(_this.cur_num == _this.total_page_page){
				return;
			}else{
				_this.cur_num = _this.total_page_page;
				_this.form_cur_input_hidden.val(_this.cur_num);
				_this.setFormDataSerilalizePageNum();
				_this.requestData(function(oData){
					// 自定义的回调函数（渲染数据之前执行）
					_this.config.btn_call_before && _this.config.btn_call_before(oData);
					_this.renderPageZone();
					_this.renderDataList();
					// 自定义的回调函数
					_this.config.btn_call && _this.config.btn_call(oData);
					// 关闭弹窗
					layer.closeAll("loading");
				});
			}
		});
	}

	// 前一页按钮绑定事件
	Pagination.prototype.bindPrevBtn = function(){
		var _this = this;
		_this.form_btn_prev.click(function() {
			if(_this.cur_num == 1){
				return;
			}else{
				_this.cur_num -= 1;
				if(_this.cur_num <= 1){
					_this.cur_num = 1;
				}
				_this.form_cur_input_hidden.val(_this.cur_num);
				_this.setFormDataSerilalizePageNum();
				_this.requestData(function(oData){
					// 自定义的回调函数（渲染数据之前执行）
					_this.config.btn_call_before && _this.config.btn_call_before(oData);
					_this.renderPageZone();
					_this.renderDataList();
					// 自定义的回调函数
					_this.config.btn_call && _this.config.btn_call(oData);
					// 关闭弹窗
					layer.closeAll("loading");
				});
			}
		});
	}

	// 后一页按钮绑定事件
	Pagination.prototype.bindNextBtn = function(){
		var _this = this;
		_this.form_btn_next.click(function() {
			if(_this.cur_num == _this.total_page_page){
				return;
			}else{
				_this.cur_num += 1;
				if(_this.cur_num >= _this.total_page_page){
					_this.cur_num = _this.total_page_page;
				}
				_this.form_cur_input_hidden.val(_this.cur_num);
				_this.setFormDataSerilalizePageNum();
				_this.requestData(function(oData){
					// 自定义的回调函数（渲染数据之前执行）
					_this.config.btn_call_before && _this.config.btn_call_before(oData);
					_this.renderPageZone();
					_this.renderDataList();
					// 自定义的回调函数
					_this.config.btn_call && _this.config.btn_call(oData);
					// 关闭弹窗
					layer.closeAll("loading");
				});
			}
		});
	}

	// 跳转按钮绑定事件
	Pagination.prototype.bindJumpBtn = function(){
		var _this = this;
		_this.form_btn_go.click(function() {
			var sVal = $.trim(_this.form_btn_go_inp.val());
			var bBoo = _this.checkPageInput(sVal);
			if(!bBoo){
				layerPc.success({
				   title: '提示信息',
				   tip_ok_con: '请输入正整数',
				   tip_type: 2,
				   time: 3000,
				   call: function(){
				   		_this.form_btn_go_inp.val("");
				   }
				});
			}else{
				var iPageNum = sVal - 0;
				if(iPageNum > _this.total_page_page){
					layerPc.success({
					   title: '提示信息',
					   tip_ok_con: '请输入'+ _this.total_page_page +'以内的正整数',
					   tip_type: 2,
					   time: 3000,
					   call: function(){
					   		_this.form_btn_go_inp.val("");
					   }
					});
				}else{
					if(iPageNum != _this.cur_num){
						_this.cur_num = iPageNum;
						_this.form_cur_input_hidden.val(_this.cur_num);
						_this.setFormDataSerilalizePageNum();
						_this.requestData(function(oData){
							// 自定义的回调函数（渲染数据之前执行）
							_this.config.btn_call_before && _this.config.btn_call_before(oData);
							_this.renderPageZone();
							_this.renderDataList();
							// 自定义的回调函数
							_this.config.btn_call && _this.config.btn_call(oData);
							// 关闭弹窗
							layer.closeAll("loading");
						});
					}
				}
			}
		});
	}

	// 跳转页码输入框绑定事件
	Pagination.prototype.bindJumpInput = function(){
		var _this = this;
		_this.form_btn_go_inp.keyup(function(event) {
			var oEv = event || window.event;
			if(oEv.keyCode == 13){
				_this.form_btn_go.click();
			}
		});
	}

	// 绑定页码条数事件--每页显示条数
	Pagination.prototype.bindPageSizeChange = function(){
		var _this = this;
		_this.form_page_size.change(function(){
			var oCur = $("#page_page_size option:selected");
			_this.page_size = oCur.html() - 0;
			_this.page_page_size_hidden.val(_this.page_size);
			_this.setFormDataSerilalizePageSize();
			_this.cur_num = 1;
			_this.form_cur_input_hidden.val(1);
			_this.setFormDataSerilalizePageNum();
			_this.requestData(function(oData){
				// 自定义的回调函数（渲染数据之前执行）
				_this.config.btn_call_before && _this.config.btn_call_before(oData);
				_this.renderPageZone();
				_this.renderDataList();
				// 自定义的回调函数
				_this.config.btn_call && _this.config.btn_call(oData);
				// 关闭弹窗
				layer.closeAll("loading");
			});
		})
	}

	// 检查输入框输入内容
	Pagination.prototype.checkPageInput = function(str){
		var _this = this;
		var rReg = /^\+?[1-9][0-9]*$/;
		return rReg.test(str);
	}

	return Pagination;
});
